//
//  GranwinAPKit.h
//  GranwinAPKit
//
//  Created by (╹◡╹) on 2019/5/7.
//  Copyright © 2019 granwin. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "GWDevice.h"
#import "GWCallBack.h"

NS_ASSUME_NONNULL_BEGIN

typedef void (^LinkkitBooleanResultBlock)(BOOL succeeded, NSError * _Nullable error);

typedef NS_ENUM(UInt8, GWErrorCode) {
    GWErrorCodeNoStart,
    GWErrorCodeTimeout,
    GWErrorCodeNoSupportAutoConnectWiFi,
    GWErrorCodeConfigureWiFiFailed
};

@protocol GranwinAPKitDelegate <NSObject>

//收到数据回调
- (void)onNotify:(nonnull NSString *)connectId topic:(nonnull NSString *)topic data:(id _Nullable)data;

@end

@interface GranwinAPKit : NSObject

@property (nonatomic, weak) id <GranwinAPKitDelegate> delegate;

+ (GranwinAPKit *)shared;

//启动SDK
- (void)start;

//配置SDK
- (void)initALiIotWithProductKey:(NSString *)productKey
                  withDeviceName:(NSString *)deviceName
                withDeviceSecret:(NSString *)deviceSecret
               withProductSecret:(NSString *)productSecret
                     resultBlock:(LinkkitBooleanResultBlock)resultBlock;

//下发数据
- (void)publish:(NSString *)topic
           data:(NSData *)data
    resultBlock:(LinkkitBooleanResultBlock)resultBlock;

//订阅主题
- (void)subscribe:(NSString *)topic resultBlock:(LinkkitBooleanResultBlock)resultBlock;

//取消订阅主题
- (void)unsubscribe:(NSString *)topic resultBlock:(LinkkitBooleanResultBlock)resultBlock;

- (void)destroy;

//连接到WiFi热点
- (void)connectDeviceHot:(NSString *)deviceHot hotPassword:(NSString *)pwd didFinish:(GWCallBack *)callBack;

//配置设备WiFi
- (void)setDeviceNetwork:(NSString *)wifiSSID wifiPassword:(NSString *)wifiPassword timeoutSec:(NSTimeInterval)sec didFinish:(GWCallBack <GWDevice *> *)callBack;

//停止配置WiFi
- (void)stopSetDeviceNetwork;

- (void)bindDeviceWithUserId:(NSNumber *)userId withDeviceId:(NSString *)deviceId withDeviceName:(NSString *)deviceName didFinish:(GWCallBack *)callBack;

- (void)test;

@end

NS_ASSUME_NONNULL_END
